<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>系统登录</title>
</head>
<body>
<h1>这是后台管理系统。请登录！</h1>
<input id="username" name="username" placeholder="用户名"><br><br>
<input id="password" name="password" type="password" placeholder="密码"><br><br>
<input type="button" value="登录" onclick="login()">
<script src="./assets/jquery-v3.7.1/jquery.min.js"></script>
<script>

    function login() {
        $.post({
            url: "./login",
            contentType: "application/json",
            data: JSON.stringify({username: $('#username').val(), password: $('#password').val()}),
            success: function (result) {
                console.log(result);
                if (result.code == 0) {
                    localStorage.setItem('__authorization__', result.data)
                    const expireTime = new Date()
                    expireTime.setTime(expireTime.getTime() + (30 * 24 * 60 * 60 * 1000))
                    document.cookie = "__authorization__=" + result.data + ";expires=" + expireTime.toUTCString()
                    location.reload()
                } else {
                    alert('用户名或密码错误！')
                }
            }
        })
    }
</script>
</body>
</html>
